< previous page page_415 next page >

Page 415
e10a6a0a59f035e870d90cca05b85fce.gif
            obj.Draw pic
        Next obj
    End If
End Sub

' Find an object that contains this point.
Public Function ObjectAt( _
    ByVal X As Single, ByVal Y As Single) As Object
Dim obj As Object

    Set ObjectAt = Nothing

    ' Stop if we don't contain the point.
    If X < xmin Or X > xmax Or _
       Y < ymin Or Y > ymax _
       Then Exit Function

    ' Find the object.
    If Objects Is Nothing Then
        ' This is not a leaf node.
        ' Search our children.
        If Y > ymid Then
            If X < xmid Then
                ' Search the northwest child.
                Set ObjectAt = NWchild.ObjectAt(X, Y)
            Else
                ' Search the northeast child.
                Set ObjectAt = NEchild.ObjectAt(X, Y)
            End If
        Else
            If X < xmid Then
                ' Search the southwest child.
                Set ObjectAt = SWchild.ObjectAt(X, Y)
            Else
                ' Search the southeast child.
                Set ObjectAt = SEchild.ObjectAt(X, Y)
            End If
        End If
    Else
        ' This is a leaf node.
        ' Search the objects it contains.
        For Each obj In Objects
            If obj.IsAt(X, Y) Then
                Set ObjectAt = obj
                Exit Function
            End If
        Next obj
    End If
End Function

 
< previous page page_415 next page >